#ifndef VFSYSTEM_H_INCLUDED
#define VFSYSTEM_H_INCLUDED


#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

#include <MemoryManager.h>
#include <Vector_inside.h>



#define INOUT
#define I_N_BLOCKS              (I_N_PAGESIZE/sizeof(void*))/*Num of blocks in each inderection level*/
#define I_N_ARR_Default_Size    (30*sizeof(void*))
#define PAGEREQEST(x)           (x)?         1:0
#define I_N_PAGESIZE            (32)
#define I_N_LEVELS              (3)/*Total degree of levels for tripple inderection will be 4*/
#define PATH                    (30)
#define fdlistsize              (10)



typedef enum i_mode {VFS_DERECTORY,VFS_FILE,VFS_SPECIAL_CHARACTER,VFS_SPECIAL_BLOCK,VFS_HLINK,VFS_SLINK} i_mode;
typedef enum inderect_level {VFS_DIRECT,VFS_INDERIECT,VFS_DOUB_INDIRECT,VFS_TRP_INDERECT} ind_lvl;
typedef enum flag_S{n,S_READ,S_WRITE,p,S_CREATE} flag_S;
typedef double           i_time;
typedef  void**          indPtr;


typedef enum i_node_Err {
    VFS_OK                                   =0,
    VFS_FILE_CREATION_PROBLEMS               =10,
    VFS_BLOCK_CREATION_PROBLEMS              =20,
    VFS_INDER_LEVEL_CREATION_PROBLEM         =30,
    VFS_ALL_PLACES_IN_DIRECTORY_FILLED       =40,
    VFS_FILEARRAY_INIT_PROBLEMS              =50,
    VFS_ARRAY_OF_FILES_UPDATION_PROBLEM      =60,
    VFS_PARENT_DIRECTORY_NOT_FOUND           =70,
    VFS_MKDIR_DIRECTORY_ALREADY_EXIST        =80,
    VFS_PATH_NOT_EXISTS                      =90,
    VFS_PROBLEMS_FD_FILE_OPENING             =100,
    VFS_PROBLEMS_WITH_DATA_ALLOCATION_WRITE  =110,
    VFS_NO_FILE_PROVEDED_TO_WRITE            =120,
    VFS_ILLIGAL_FDCOUNTER_WRITE              =130,
    VFS_NOTHING_TO_WRITE                     =140,
    VFS_NO_FILE_TO_READING                   =150,
    VFS_ILLIGA_POSITION_READING              =160,
    VFS_NO_BUFFER_SUPPLYED_READ              =170,
    VFS_SIZE_FOR_READING_OUT_OF_BOUNDARIES   =180,
    VFS_FILE_ALREADY_EXISTS                  =190,
    VFS_ONE_OF_ARGUMENTS_IS_WRONG_LN         =200,
    VFS_ONE_OF_ARGUMENTS_IS_WRONG_RM         =210,
    VFS_GENERAL_BUG                          =-1,
    VFS_WRONG_OBJECT                         =220
}inode_Err;


typedef struct I_Block
{
   size_t          Link_count;
   indPtr          N_directArr[I_N_LEVELS];/*Its arrays of object and each object is arrays of void* pointers*/
   size_t          numofptr;/*how many pages connected exept itself and parent*/
   size_t          sizeData;/*n bytes of Page* number of pages connected*/
}
I_Block;


typedef struct VSF_i_node i_node;
struct VSF_i_node
{
    i_mode                  mode;
    uid_t                   uid;
    gid_t                   gid;
    unsigned short          permision;/*i_flags*/
    i_time                  atime;/*last access*/
    i_time                  mtime;/*last modified*/
    I_Block*                i_n_blk;/*MAX constains arrayofinderection levels*/
    char                    i_Filename[PATH];/*file name not including all path*/
};

typedef struct file_descriptor
{
    i_node* node;
    size_t  pos;
} FD;

extern int fdcounter;
extern FD*         fdlist[fdlistsize];
extern MMheap*     Heap;


/*THe full path has to be provided used only for files and HD_Links*/
inode_Err VFS_ln (i_mode mode,char*  parent_item,char*  destination);
/*returns 0 if succesed and advanced the position in filescriptor by number of bytes of readed*/
inode_Err VFS_read(int _fdindex,int _size, char* _buffer);
/*returns 0 if succesed and advanced the position in filescriptor by number of bytes writted*/
inode_Err VFS_write(int _fdindex,int _size, void* _buffer);
/******************************************************************************************/
int openfile(char* _PATH1,flag_S _flag);

/*Initiallizing of VFS , creates the Heap and root as golbal variables, returns error*/
inode_Err VFS_Create();
/*Create Directory according to full PATH, the PATH has to be start from '/' root*/
inode_Err VFS_mkdir(char* _PATH1);

#endif /* VFSYSTEM_H_INCLUDED*/
